package com.justgame.project.service.art.controller;

import com.justgame.project.base.annotation.ProtectAccess;
import com.justgame.project.cloud.common.constant.Result;
import com.justgame.project.cloud.common.entity.PageRequest;
import com.justgame.project.service.api.dto.ArtPageCategoryDTO;
import com.justgame.project.service.art.service.ArtPageCategoryService;
import lombok.AllArgsConstructor;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@RestController
@RequestMapping("/art/category")
@AllArgsConstructor
public class ArtPageCategoryController {

    private final ArtPageCategoryService artPageCategoryService;

    @GetMapping("/list")
    public Result<Object> getTotalCategory(PageRequest pageRequest, ArtPageCategoryDTO dto) {
        return Result.OK(artPageCategoryService.getCategoryList(dto, pageRequest));
    }

    @DeleteMapping("/del")
    @RequiresRoles("admin")
    @ProtectAccess(message = "您点的太快了,服务器跟不上了慢一点吧!")
    public Result<Object> delete(@RequestBody ArtPageCategoryDTO dto) {
        return Result.OK(artPageCategoryService.delete(dto.getIds()));
    }

    @PostMapping("/save")
    @RequiresRoles("admin")
    @ProtectAccess
    public Result<Object> addPageType(@Valid @RequestBody ArtPageCategoryDTO dto) {
        return Result.OK(artPageCategoryService.addPageType(dto));
    }

    @PostMapping("/updateById")
    @RequiresRoles("admin")
    @ProtectAccess
    public Result<Object> updateById(@RequestBody ArtPageCategoryDTO dto) {
        return Result.OK(artPageCategoryService.updateById(dto));
    }
}
